﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Fluent="clr-namespace:Fluent">
  <Fluent:ObjectToImageConverter x:Key="StringToImageConvert" />
  <Style TargetType="{x:Type Fluent:TextBox}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Fluent:TextBox}">
          <Border Width="Auto" Background="#00000000" Height="22">
            <Grid Width="Auto" Height="Auto" Background="#00000000">
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
              </Grid.ColumnDefinitions>
              <StackPanel Orientation="Horizontal" Grid.ColumnSpan="1" x:Name="stackPanel"
                          HorizontalAlignment="Left" Margin="0,0,4,0">
                <ContentPresenter x:Name="iconImage" Width="16" Height="16" VerticalAlignment="Center"
                                  Margin="3,0,0,0"
                                  Content="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource StringToImageConvert}}" />
                <TextBlock Text="{TemplateBinding Header}" TextWrapping="Wrap"
                           VerticalAlignment="Center" Margin="5,0,0,0" x:Name="textBlock" />
              </StackPanel>

              <Border Height="Auto" BorderThickness="1,1,1,1"
                      BorderBrush="{DynamicResource TextBoxBorderBrush}" x:Name="PART_ContentBorder"
                      Background="{DynamicResource TextBoxBackgroundBrush}" Grid.Column="1" Grid.ColumnSpan="1"
                      Width="{TemplateBinding InputWidth}" HorizontalAlignment="Right">

                <TextBox HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                         TextWrapping="NoWrap" BorderThickness="0,0,0,0" x:Name="PART_TextBox"
                         Background="{DynamicResource TextBoxBackgroundBrush}" />

              </Border>
            </Grid>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
              <Setter Property="Visibility" TargetName="iconImage" Value="Collapsed" />
            </Trigger>
            <Trigger Property="InputWidth" Value="NaN">
              <Setter Property="HorizontalAlignment" TargetName="PART_ContentBorder" Value="Stretch" />
            </Trigger>
            <Trigger Property="Size" Value="Middle">
              <Setter Property="Visibility" TargetName="textBlock" Value="Collapsed" />
            </Trigger>
            <Trigger Property="Size" Value="Small">
              <Setter Property="Visibility" TargetName="stackPanel" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="IsEnabled" TargetName="PART_TextBox" Value="False" />
              <Setter Property="Background" TargetName="PART_ContentBorder"
                      Value="{DynamicResource TextBoxDisabledBackgroundBrush}" />
              <Setter Property="BorderBrush" TargetName="PART_ContentBorder"
                      Value="{DynamicResource TextBoxDisabledBorderBrush}" />
              <Setter Property="BorderBrush" TargetName="PART_TextBox"
                      Value="{DynamicResource TextBoxDisabledBackgroundBrush}" />
              <Setter Property="Opacity" TargetName="iconImage" Value="0.5" />
              <Setter Property="Opacity" TargetName="textBlock" Value="0.5" />
              <Setter Property="Effect" TargetName="iconImage">
                <Setter.Value>
                  <Fluent:GrayscaleEffect />
                </Setter.Value>
              </Setter>
            </Trigger>

            <Trigger Property="IsMouseOver" Value="True">
              <Setter Property="BorderBrush" TargetName="PART_ContentBorder"
                      Value="{DynamicResource TextBoxHoverBorderBrush}" />
              <Setter Property="Background" TargetName="PART_TextBox"
                      Value="{DynamicResource TextBoxHoverBackgroundBrush}" />
              <Setter Property="Background" TargetName="PART_ContentBorder"
                      Value="{DynamicResource TextBoxHoverBackgroundBrush}" />
            </Trigger>

            <Trigger Property="IsKeyboardFocusWithin" Value="True">
              <Setter Property="BorderBrush" TargetName="PART_ContentBorder"
                      Value="{DynamicResource TextBoxHoverBorderBrush}" />
              <Setter Property="Background" TargetName="PART_TextBox"
                      Value="{DynamicResource TextBoxHoverBackgroundBrush}" />
              <Setter Property="Background" TargetName="PART_ContentBorder"
                      Value="{DynamicResource TextBoxHoverBackgroundBrush}" />
            </Trigger>


          </ControlTemplate.Triggers>

        </ControlTemplate>
      </Setter.Value>
    </Setter>
    <Setter Property="FocusVisualStyle" Value="{DynamicResource ControlStyleEmptyFocus}" />
  </Style>
</ResourceDictionary>